//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.app;

import com.ruoyi.live.app.service.ExamImportService;
import com.ruoyi.live.base.domain.LivePaperImport;
import com.ruoyi.live.base.domain.LivePaperImportProduct;
import com.ruoyi.live.base.domain.LivePaperImportProductDetail;
import com.ruoyi.live.base.domain.vo.ImportDetail;
import com.ruoyi.live.base.mapper.LivePaperImportMapper;
import com.ruoyi.live.tool.commons.ICommons;
import com.ruoyi.live.tool.utils.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping({"/paper"})
public class ExamImportController {
    @Autowired
    ExamImportService service;
    @Autowired
    LivePaperImportMapper livePaperImportMapper;

    public ExamImportController() {
    }

    @ResponseBody
    @RequestMapping({"/listPapers"})
    public List<LivePaperImport> listPapers() {
        return this.service.listPapers();
    }

    @RequestMapping({"/index"})
    public String index() {
        return "/paper/index";
    }

    @RequestMapping({"/detail"})
    public ModelAndView toDetail(Long id) {
        LivePaperImport imp = (LivePaperImport)this.livePaperImportMapper.selectById(id);
        List<LivePaperImportProduct> importProducts = this.service.loadTabList(id);
        return (new ModelAndView("paper/detail")).addObject("products", importProducts).addObject("entity", imp).addObject("persona", !ICommons.isNullOrEmpty(imp.getImportPersona()));
    }

    @ResponseBody
    @RequestMapping({"/uploadFile"})
    public Message uploadChannelFile(MultipartFile file, HttpServletRequest request) {
        try {
            return new Message(true, "上传成功", String.valueOf(this.service.doUploadFile(file, request)));
        } catch (Exception var4) {
            var4.printStackTrace();
            return new Message(false, "上传失败");
        }
    }

    @ResponseBody
    @RequestMapping({"/uploadErrorFile"})
    public Message uploadErrorFile(MultipartFile file, HttpServletRequest request, LivePaperImportProductDetail detail) {
        try {
            this.service.uploadErrorFile(file, request, detail);
        } catch (Exception var5) {
            var5.printStackTrace();
            return new Message(false, "上传失败");
        }

        return new Message(true, "");
    }

    @ResponseBody
    @RequestMapping({"/unzip"})
    public Message unzip(Long id, HttpServletRequest request) {
        try {
            this.service.unzip(id, request);
            return new Message(true, "");
        } catch (Exception var4) {
            var4.printStackTrace();
            return new Message(false, "解压失败，请确认上传的文件为zip文件");
        }
    }

    @ResponseBody
    @RequestMapping({"/checkFile"})
    public Message checkFile(Long id, HttpServletRequest request) {
        try {
            this.service.doCheckFile(id, request);
            return new Message(true, "");
        } catch (Exception var4) {
            var4.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/checkImport"})
    public Message checkImport(Long id, HttpServletRequest request) {
        try {
            this.service.checkImport(id, request);
            return new Message(true, "");
        } catch (Exception var4) {
            var4.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/checkNameList"})
    public List<Map<String, Object>> checkNameList(Long id) {
        return this.service.checkNameList(id);
    }

    @ResponseBody
    @RequestMapping({"/loadTabList"})
    public List<LivePaperImportProduct> loadTabList(Long id) {
        return this.service.loadTabList(id);
    }

    @ResponseBody
    @RequestMapping({"/loadProductDetail"})
    public List<ImportDetail> loadProductDetail(Long productId) {
        return this.service.loadProductDetail(productId);
    }

    @ResponseBody
    @RequestMapping({"/saveProductBarrage"})
    public Message saveProductBarrage(String value, Long productId) {
        try {
            this.service.saveProductBarrage(value, productId);
            return new Message(true, "");
        } catch (Exception var4) {
            var4.printStackTrace();
            return new Message(false, "");
        }
    }

    @ResponseBody
    @RequestMapping({"/insertTableEnd"})
    public Message insertTableEnd(Long id, HttpServletRequest request) {
        try {
            this.service.insertTableEnd(id, request);
            return new Message(true, "");
        } catch (Exception var4) {
            var4.printStackTrace();
            return new Message(false, "");
        }
    }
}
